package org.seefly.iprint.service.impl;

import org.seefly.iprint.entity.*;
import org.seefly.iprint.mapper.OrderItemMapper;
import org.seefly.iprint.mapper.OrdersMapper;
import org.seefly.iprint.mapper.PriceMapper;
import org.seefly.iprint.service.OrderService;
import org.seefly.iprint.vo.ItemPriceVo;
import org.seefly.iprint.vo.OrderQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private PriceMapper priceMapper;
    @Autowired
    private OrdersMapper ordersMapper;
    @Autowired
    private OrderItemMapper orderItemMapper;



    // 添加订单
    @Override
    public void addOrder(Orders od) {
        ordersMapper.insert4Key(od);
    }


    @Override
    public BigDecimal getItemPrice(ItemPriceVo vo) {
        return priceMapper.getItemPrice(vo);
    }

    
    @Override
    public BigDecimal findPrice(OrderItem oi) {
        return priceMapper.findPriceByTitle(oi);
    }
 
    @Override
    public BigDecimal findServicedPrice(OrderItem oi) {
        return priceMapper.findServicedPrice(oi);
    }

    @Override
    public void addOrderItem(OrderItem e) {
        orderItemMapper.insertSelective(e);
    }



    /**
    * 过去七天中每天的销售额，按天分类
    */
    @Override
    public List<SalesData> salesData() {
        return ordersMapper.get7DaysSaleData();
    }
    
    /**
     * 过去七天中各类商品的销售数量，按商品分类
     */
    @Override
    public List<SalesCount> getSalesCount() {
        return ordersMapper.get7DaysSaleCount();
    }
    /**
     * 获取过去七天中各类商品销售金额，按商品分类
     */
    @Override
    public List<EchartsPojo> getSalesPriceCount() {
        return ordersMapper.get7DaysSalePriceCount();
    }
    


    @Override
    public Integer getOrdersCount(String status) {
        return ordersMapper.findOrdersCountByStatus(status);
    }
    
    @Override
    public List<OrderItem> getOrdersList(Integer currPage, Integer pageSize, String status) {
        int start = (currPage - 1) * pageSize;
        List<OrderItem> list = ordersMapper.findOrdersByStatus(start,pageSize,status);
        return list;
    }
    


    
    @Override
    public PageBean<OrderItem> getOrdersByCondition(OrderQueryVo vo) {
        PageBean<OrderItem> pb = new PageBean<>();
        pb.setCurrPage(vo.getCurrPage());
        vo.setCurrPage((vo.getCurrPage()-1)*vo.getPageSize());
        //查询实体
        List<OrderItem> list = ordersMapper.getOrdersByCondition(vo);
        pb.setList(list);
        //查询数量
        Integer count = ordersMapper.getOrdersCountByCondition(vo);
        pb.setTotalCount(count);
        pb.setPageSize(vo.getPageSize());
        //pb.set
        return pb;
    }
    
   @Override
    public OrderItem getOrderItem(Integer id) {
        return orderItemMapper.selectByPrimaryKey(id);
    }
   
   @Override
    public void updateOrderStatus(Integer id, String success) {
       ordersMapper.updateStatus(id,success);
    }
    
}
